define(function (require, exports) {
	/**
	 * 页面加载完成时触发
	 * @param hashCode 路由ID
	 * @param data 传递数据对象
	 * @param cite 页面站点信息
	 */
	exports.ready = function (hashCode, data, cite) {
		yufp.custom.vue({
			el: cite.el,
			data: function () {
				var eventTypeOption = [{ key: 'G', value: '普通事件' },
				{ key: 'F', value: '文件事件' }]

				var _this = this;

				return {
					tbHeight:'0',
					tbHeight1:'0',
					searchFormdata: {},
					searchFlowFormdata: {},
					appOption: [],
                    groupOption: [],
                    relOption:[{key:"D",value:"依赖"},{key:"T",value: "触发"}],
					appNameDisabled: false,
					treeDataUrl: "api/use/plats/event/queryTreeList",
					dataUrl: 'api/use/monitor/eventLog/queryAllList',
					flowDataUrl:  'api/use/monitor/eventLog/queryAllListByFlows',
					recordBtnShow: false,
					deleteBtnShow: false,
					addBtnShow: false,
					currentClickNode: {},
					eventHisLog: "basicEventLog",
					formdata: {},
					async: false,
					param: { UNITID: '0000', LEVELUNIT: '1' },
					height: yufp.frame.size().height -167,
					dialogVisible: false,
					eventTypeOption: eventTypeOption,
					viewTitleArrry: ['普通事件监控'],
					viewTitle: '',
					isAppNode: false,
					eventFiles: [],
					currAppNode: {},
					updateFnShow1: !yufp.session.checkCtrl('updateFn1'),
					updateFnShow2: !yufp.session.checkCtrl('updateFn2'),
					intervalSelection: {
						key: '60000',
						label: '60秒'
					},
					requiredRule: [{ required: true, message: '必填项' }],
					refreshIntervalOptions: [{ key: '864000000', label: '不自动刷新' }, { key: '10000', label: '10秒' }, { key: '20000', label: '20秒' }, { key: '30000', label: '30秒' }, { key: '60000', label: '60秒' }],
					loading: false
				};
			},
			mounted() {
				var _this = this;
				
				
				_this.$nextTick(function(){
						var tableBox = _this.$refs.tableBox;
						let a = tableBox.getBoundingClientRect().top + 28;
						var theight = `calc(100vh - ${a}px - 64px)`;
						var theight1 = `calc(100vh - ${a}px - 84px)`;
						_this.tbHeight1 = theight1;	
						_this.tbHeight = theight;		
				});
				_this.queryAppList();
				// this.refreshTable(_this.refreshInterval)
			},
			watch: {
				refreshInterval(val) {
					var _this = this;
					clearInterval(_this.setIntervalId);
					_this.setIntervalId = setInterval(fn, _this.refreshInterval);
					function fn() {
						clearInterval(_this.setIntervalId);
						_this.$refs.refTable.remoteData("");
						_this.setIntervalId = setInterval(fn, _this.refreshInterval);
					}
				}
			},
			methods: {

			queryAppList: function () {
            	 var _this = this;
            	  yufp.service.request({
            		 method: 'GET',
            		  url: "api/use/plats/apps/getTreeWftList",
            		  ata: {},
            		  async: false,
            		 callback: function (code, message, response) {
            		  if (response.code != 0) {
            				 _this.$message(response.message);
            			 } else {
            				  _this.appOption.splice(0);
            				 for (let i = 0; i < response.data.length; i++) {
            					  if (response.data[i].appCode != '0000') {
            							 _this.appOption.push({ key: response.data[i].appCode, value: response.data[i].appName });
            					     }

            					}
            				 }

            				  }
            					});
            				},

				changeApp: function (val) {
				        var _this = this;
				        _this.groupOption = [];
                         _this.searchFlowFormdata.groupCode = "";
            			var paramObj = { appCodeEq: val };
                    	 yufp.service.request({
                    		 method: 'GET',
                    		 url: "api/use/plats/workflow/queryWftGrpList",
                    		 data: paramObj,
                    		 async: false,
                    		 callback: function (code, message, response) {
                    			 if (response.code != 0) {
                    					 _this.$message(response.message);
                    				 } else {
                    					 for (let i = 0; i < response.data.length; i++) {
                    					    _this.groupOption.push({ key: response.data[i].groupCode, value: response.data[i].groupName });
                                                }
                    						}
                    			}
                     });
            		},

			     markFile: function (currentData) {
                			 this.markFOpr(currentData, 0);
                 },

                  clearnMarkFile: function (currentData) {
                		 this.markFOpr(currentData, 1);
                 },

                 markFOpr: function (data, opr) {

                	 var _this = this;
                	  let urlparam = "";

                	 if (opr == 0) {
                			 urlparam = 'api/use/monitor/eventLog/markEventFile';
                	 } else {
                		 urlparam = 'api/use/monitor/eventLog/clearEventFile';
                	 }


                	 yufp.service.request({
                		 method: 'POST',
                		 url: urlparam,
                		 data: {
                			 appCode: data.appCode,
                			 eventCode: data.eventCode,
                			 cycleTime: data.cycleTime,
                			 fileId: data.fileId
                		 },
                		 callback: function (code, message, response) {

                		 if (response.code === 0) {
                								_this.viewDataFn(data);
                								_this.$refs.refTable.remoteData("");
                								_this.$refs.refFlowEventTable.remoteData("");
                								_this.$message('操作成功');

                		 } else {
                			 _this.$message(response.message);
                		 }
                	 }
                	});
                },

				formartCycleDate: function (val) {
					if (val == null || val === '') {
						return "";
					}
					var d = new Date(val);
					var year = d.getFullYear();
					var month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
					var date = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();

					return year + "" + month + "" + date;
				},

				/**
				 * 单击选择
				 */
				cellClick: function (row, event, column, index) {
					var _this = this;
					if (row) {
						_this.$refs.refTable.toggleRowSelection(row);
					}
				},

				cancelFn: function () {
					this.dialogVisible = false;
				},

				viewDataFn: function (data) {
					const _this = this;
					_this.dialogVisible = true;
					const param = {};
					param.cycleTime = data.cycleTime;
					param.appCode = data.appCode;
					param.eventCode = data.eventCode;
					_this.$nextTick(function () {
						yufp.service.request({
							method: 'GET',
							url: "api/use/monitor/eventLog/queryFileList",
							data: param,
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									_this.eventFiles.splice(0);

									for (let i = 0; i < response.data.length; i++) {
										_this.eventFiles.push(response.data[i]);
									}
								}

							}
						});
					});

				},


				selectIntervalFn: function (val) {
					var _this = this;
					if (val instanceof Object) {
						_this.refreshInterval = val.key
					} else {
						_this.refreshInterval = val
					}
				},
				refreshTable: function () {
					var _this = this;

					_this.setIntervalId = setInterval(fn, _this.refreshInterval);
					function fn() {
						clearInterval(_this.setIntervalId);
						_this.$refs.refTable.remoteData("");
						_this.setIntervalId = setInterval(fn, _this.refreshInterval);
					}
				},
				/**
				 * 修改
				 */
				markEventList: function (type) {
					var _this = this;
					var selections;
                    if(type==='event'){
                    	selections = _this.$refs.refTable.selections;

                    }else{
                        selections = _this.$refs.refFlowEventTable.selections;
                    }

                    if (selections.length < 1) {
                                 _this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
                                  return;
                     }

					_this.loading = true;
					var len = selections.length;
					let urlparam = "api/use/monitor/eventLog/markEventFileList";
					yufp.service.request({
						method: 'POST',
						url: urlparam,
						data: { data: selections },
						callback: function (code, message, response) {
							_this.loading = false;
							if (response.code === 0) {
								_this.$message('操作成功');
								 if(type==='event'){
								     _this.$refs.refTable.remoteData("");
								 }else{
								     _this.$refs.refFlowEventTable.remoteData("");
								 }

							} else {
								_this.$message(response.message);
							}
						}
					})
				},

				/**
				 * 清除事件
				 */
				cleanEventList: function (type) {
					var _this = this;
					var selections;
					if(type==='event'){
						selections = _this.$refs.refTable.selections;
					}else{
						selections = _this.$refs.refFlowEventTable.selections;
					}

					if (selections.length < 1) {
						_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
						return;
					}
					var len = selections.length;
					_this.loading = true;
					let urlparam = "api/use/monitor/eventLog/clearEventFileList";
					yufp.service.request({
						method: 'POST',
						url: urlparam,
						data: { data: selections },
						callback: function (code, message, response) {
							_this.loading = false;
							if (response.code === 0) {
								_this.$message('操作成功');
								 _this.$refs.refTable.remoteData("");
								 _this.$refs.refFlowEventTable.remoteData("");
							} else {
								_this.$message(response.message);
							}
						}
					})
				},



				recordEvent: function (currentData,type) {
					var _this = this;

					var data = currentData;
					let urlparam = 'api/use/monitor/eventLog/markEvent';

					yufp.service.request({
						method: 'POST',
						url: urlparam,
						data: {
							appCode: data.appCode,
							eventCode: data.eventCode,
							cycleTime: data.cycleTime
						},
						callback: function (code, message, response) {

							if (response.code === 0) {
								_this.$message('操作成功');
								_this.$refs.refTable.remoteData("");
                                _this.$refs.refFlowEventTable.remoteData("");

							} else {
								_this.$message(response.message);
							}
						}
					});
				},
				deleteEvent: function (currentData) {
					var _this = this;

					var data = currentData;
					let urlparam = 'api/use/monitor/eventLog/deleteMarkEvent';

					yufp.service.request({
						method: 'POST',
						url: urlparam,
						data: {
							appCode: data.appCode,
							eventCode: data.eventCode,
							cycleTime: data.cycleTime
						},
						callback: function (code, message, response) {

							if (response.code === 0) {
								_this.$message('操作成功');
    	                         _this.$refs.refTable.remoteData("");
                                 _this.$refs.refFlowEventTable.remoteData("");

							} else {
								_this.$message(response.message);
							}
						}
					});
				},
				selectEvent: function (selection) {
					var _this = this;
					if (selection[0] == null) {
						_this.recordBtnShow = false;
						_this.deleteBtnShow = false
					} else if (selection[0].recordTime !== null) {
						_this.deleteBtnShow = true
					} else {
						_this.recordBtnShow = true
					}
				},
				stateFormatter: function (row, column, cellValue) {
					if (cellValue !== null) {
						return "已记录"
					} else {
						return "未记录"
					}
				},
				/**
				 * 点击树的结点，加载对应的数据
				 */
				/**
				 * 点击树的结点，加载对应的数据
				 */
				nodeClickFn: function (nodeData, node, self) {

					var _this = this;
					_this.currentClickNode = nodeData;
					var appCode = "";
					let folderCode = "";
					if (nodeData.nodeType === 'R') {
						_this.isAppNode = false;
						_this.appNameDisabled = false
						_this.searchFormdata.appName = '';
						appCode = "";

					} else if (nodeData.nodeType === 'A') {

						_this.isAppNode = true;
						_this.currAppNode = nodeData;
						_this.appNameDisabled = true;
						_this.searchFormdata.appName = nodeData.appName;
						appCode = nodeData.currentNodeId;
					} else {
						_this.isAppNode = true;
						_this.currAppNode = nodeData;
						_this.appNameDisabled = true;
						_this.searchFormdata.appName = nodeData.appName;
						appCode = nodeData.appCode;
						folderCode = nodeData.currentNodeId;
					}
					var paramObj = {};
					_this.searchFormdata.appCode = appCode;
					//_this.searchFormdata2.appCode = appCode;
					_this.searchFormdata.folderCode = folderCode;

					var param = { condition: JSON.stringify(_this.searchFormdata) };
					_this.$refs.refTable.remoteData(param);

				}
			},
		});
	};
});